<?php
// +----------------------------------------------------------------------
// | 有小象汇 自研正版源码 赋能开发者
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 http://www.uxphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 有小象汇并不是自由软件，未经许可不能去掉有小象汇相关版权
// +----------------------------------------------------------------------
// | Author:  有小象汇
// +----------------------------------------------------------------------

namespace app\adminapi\controller\v1\car;

use app\adminapi\controller\AuthController;
use app\services\car\BaseSuggestServices;
use think\facade\App;

class BaseSuggest extends AuthController
{
    public function __construct(App $app,BaseSuggestServices $services)
    {
        parent::__construct($app);
        $this->services = $services;
    }

    /**
     * 获取列表
     * @return mixed
     */
    public function getList() {
        $where = $this->request->getMore([
            ['keyword',''],//搜索条件
            ['status',0],
            ['field_key','']
        ]);
        $list = $this->services->getList($where,'*','true');
        return app('json')->success($list);
    }

    /**
     * 删除
     * @param $id
     * @return mixed
     */
    public function del($id) {
        return app('json')->success($this->services->del((int)$id));
    }

    /**
     * 处理建议
     * @return \think\Response
     * @throws \FormBuilder\Exception\FormBuilderException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function suggestDispose(){
        $data = $this->request->getMore([
            ['id','']
        ]);
        if(!$data['id']) return app('json')->fail('缺少参数');
        return app('json')->success($this->services->suggestDispose((int)$data['id']));
    }

    /**
     * 保存
     * @return \think\Response
     */
    public function save(){
        $data = $this->request->postMore([
            ['id',''],
            ['status','']
        ]);
        return app('json')->success($this->services->status((int)$data['id'],(int)$data['status']));
    }
}
